import { Model, DataTypes } from 'sequelize';
import { sequelize } from './db';

class Live extends Model {
  public id!: string;
  public streamerId!: string;
  public startTime!: Date;
  public duration?: number;
  public title?: string;
  public path?: string;
  public status?: string;
}

Live.init(
  {
    id: {
      type: DataTypes.STRING,
      primaryKey: true,
    },
    streamerId: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    startTime: {
      type: DataTypes.DATE,
      allowNull: false,
    },
    duration: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    title: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    path: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    status: {
      type: DataTypes.STRING,
      allowNull: true,
      defaultValue: '进行中',
    },
  },
  {
    sequelize,
    modelName: 'Live',
    timestamps: true,
    freezeTableName: true
  }
);

export default Live;